home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright (c) 2007-2008 Alloysoft, LLC. All rights reserved.
- http://www.alloysoft.com
- */
- var http_request;
- var queue_request;
- var timerID=0;
- var timerQueue=0;
- var queueID=-1;
- var lastQueueEventId=0;
- var pendingRequests=new Array();
- var usePersistentConnection=true;
- var loggingEnabled=true;
- var isMobileSafari=true;
- var currentArtist="";
- var currentAlbum="";
- var currentTitle="";
- var currentRating=0;
- var currentVolume=0;
- var playingState;
- var playPosition=0;
- var playlistPosition=-1;
- var shuffleState=false;
- var repeatState=false;
- var speakers=new Array();
- var currentBrowsePath="";
- var currentSearchKeywords="";
- var currentArtURL="no_artwork.jpg";
- var searchInput="";
- var searchInputTimer;
- var elaspedPlayTime=0;
- var currentRequest="";
- var requestTimeout=5000;
- var isRequestPending=false;
- var isQueueRequestPending=false;
- var link_request;
- var isLinkRequestPending=false;
- var linkRecoveryRequests=new Array();
- var timeoutRequest=0;
- var timeoutCheckQueue=0;
- var timeoutPing=0;
- var timeoutPingResponse=0;
- var timeoutVerifyPingQueue=0;
- var linkRecoveryActive=false;
- var receivedPingResponse=false;
- var lastEventTime=new Date();
- var linkRecoveryStart=new Date();
- var currentWindowWidth=0;
- var showingMediaLib=false;
- var showingPlaylist=false;
- var showingSpeakers=false;
- var showingSearchResults=false;
- var showingMediaLibSearch=false;
- var showingMediaLibActions=false;
- var showingMediaLibAlphaJump=false;
- var showingMediaLibSearchResults=false;
- var showingSubControls=false;
- var lastMonitorTime=new Date();
- var itemsPerPage=35;
- var volumeIncrement=10;
- var slideSpeed=4;
- var mediaLibStart=0;
- var mediaLibLength=0;
- var playlistStart=0;
- var playlistLength=0;
- var showPlaylistItemOnPageLoad=false;
- var browseHistory=new Array();
- var currentActionItem="";
- var useMultipleSpeakers=false;
- var ignoreNextVolumeUpdate=false;
- var ignoreNextRatingUpdate=false;
- var navHistory=new Array();
- var navHash="#";
- var navCurrent="";
- BrowseHistoryEntry=function(){
- this.path="";
- this.search=false;
- this.start=0;
- };
- function createHTTPRequest(){
- var _1=null;
- if(window.XMLHttpRequest){
- _1=new XMLHttpRequest();
- if(_1.overrideMimeType){
- _1.overrideMimeType("text/xml");
- }
- }else{
- if(window.ActiveXObject){
- try{
- _1=new ActiveXObject("Msxml2.XMLHTTP");
- }
- catch(e){
- try{
- _1=new ActiveXObject("Microsoft.XMLHTTP");
- }
- catch(e){
- }
- }
- }
- }
- return _1;
- }
- function sendRequest(_2){
- if(linkRecoveryActive){
- if(linkRecoveryRequests.length>0&&_2==linkRecoveryRequests[linkRecoveryRequests.length-1]){
- return;
- }
- linkRecoveryRequests.push(_2);
- return;
- }
- if(isRequestPending){
- if(_2==currentRequest){
- return;
- }
- pendingRequests.push(_2);
- return;
- }
- if(http_request&&http_request.readyState!=4){
- http_request.abort();
- }
- http_request=createHTTPRequest();
- isRequestPending=true;
- currentRequest=_2;
- http_request.open("POST","/xml",true);
- http_request.setRequestHeader("Cache-Control","no-cache");
- http_request.setRequestHeader("If-Modified-Since","Wed, 15 Nov 1995 00:00:00 GMT");
- http_request.onreadystatechange=processResponse;
- http_request.send("xml="+_2);
- }
- function _cancelRequest(){
- if(!isRequestPending||currentRequest==""){
- return;
- }
- if(timeoutRequest){
- clearTimeout(timeoutRequest);
- timeoutRequest=0;
- }
- if(http_request){
- http_request.abort();
- http_request=null;
- }
- isRequestPending=false;
- }
- function createQueue(){
- if(timerQueue){
- clearInterval(timerQueue);
- timerQueue=0;
- }
- if(queue_request){
- queue_request.abort();
- queue_request=null;
- isQueueRequestPending=false;
- }
- queueID=-1;
- lastQueueEventId=0;
- queue_request=createHTTPRequest();
- queue_request.open("POST","/q",true);
- queue_request.setRequestHeader("Cache-Control","no-cache");
- queue_request.setRequestHeader("If-Modified-Since","Wed, 15 Nov 1995 00:00:00 GMT");
- queue_request.onreadystatechange=processQueueCreateResponse;
- queue_request.send("id=new");
- }
- function verifyQueueActive(){
- if(!usePersistentConnection||linkRecoveryActive||queueID<1){
- return;
- }
- if(!queue_request||!isQueueRequestPending){
- getQueuedEvents();
- }else{
- if(queue_request&&queue_request.readyState==0){
- isQueueRequestPending=false;
- getQueuedEvents();
- }
- }
- }
- function getQueuedEvents(){
- if(isQueueRequestPending){
- return;
- }
- try{
- if(queue_request&&queue_request.readyState!=4){
- queue_request.abort();
- queue_request=null;
- isQueueRequestPending=false;
- }
- }
- catch(e){
- }
- if(queueID==-1){
- createQueue();
- return;
- }
- queue_request=createHTTPRequest();
- isQueueRequestPending=true;
- queue_request.open("POST","/q",true);
- queue_request.setRequestHeader("Cache-Control","no-cache");
- queue_request.setRequestHeader("If-Modified-Since","Wed, 15 Nov 1995 00:00:00 GMT");
- queue_request.onreadystatechange=processQueueResponse;
- if(usePersistentConnection){
- queue_request.send("id="+queueID+"&lastEventId="+lastQueueEventId);
- }else{
- queue_request.send("id="+queueID);
- }
- }
- function processQueueCreateResponse(){
- try{
- if(queue_request.readyState!=4){
- return;
- }
- if(queue_request.status&&queue_request.status!=200){
- return;
- }
- queueID=parseInt(queue_request.responseText);
- lastQueueEventId=0;
- try{
- requestInitialState();
- }
- catch(e){
- writeLog("Error requesting initial state",e);
- }
- if(timerQueue){
- clearInterval(timerQueue);
- timerQueue=0;
- }
- if(usePersistentConnection){
- getQueuedEvents();
- timerQueue=setInterval(verifyQueueActive,5000);
- }else{
- timerQueue=setInterval(getQueuedEvents,1000);
- }
- }
- catch(e){
- return;
- }
- }
- function processQueueResponse(){
- try{
- if(queue_request.readyState!=4){
- return;
- }
- isQueueRequestPending=false;
- if(queue_request.status&&queue_request.status==404){
- lastEventTime=new Date();
- if(linkRecoveryActive){
- exitLinkRecovery();
- }
- createQueue();
- return;
- }else{
- if(queue_request.status&&queue_request.status!=200){
- return;
- }
- }
- if(!queue_request.status||queue_request.status!=200){
- return;
- }
- if(!queue_request.responseXML){
- return;
- }
- var _3=queue_request.responseXML.documentElement;
- if(!_3){
- return;
- }
- lastEventTime=new Date();
- if(linkRecoveryActive){
- exitLinkRecovery();
- }
- if(_3.attributes){
- var _4=_3.attributes.getNamedItem("lastEventId");
- if(_4){
- lastQueueEventId=parseInt(_4.nodeValue);
- if(lastQueueEventId==NaN){
- lastQueueEventId=0;
- }
- }
- }
- var _5=_3.getElementsByTagName("event");
- for(var i=0;i<_5.length;i++){
- try{
- onMessage(_5[i].firstChild);
- }
- catch(e){
- var _7="";
- if(_5[i]&&_5[i].firstChild&&_5[i].firstChild.tagName){
- _7=_5[i].firstChild.tagName;
- }
- writeLog("Error processing message "+_7,e);
- }
- }
- if(usePersistentConnection){
- getQueuedEvents();
- }
- }
- catch(e){
- isQueueRequestPending=false;
- writeLog("",e);
- return;
- }
- }
- function onMessage(_8){
- if(_8.tagName=="CurrentMediaChangedEvent"){
- processCurrentMediaChangedEvent(_8);
- }else{
- if(_8.tagName=="PlayingStateChangedEvent"){
- processPlayingStateChangedEvent(_8);
- }else{
- if(_8.tagName=="VolumeChangedEvent"){
- processVolumeChangedEvent(_8);
- }else{
- if(_8.tagName=="PlaylistChangedEvent"){
- processPlaylistChangedEvent();
- }else{
- if(_8.tagName=="PlaylistPositionChangedEvent"){
- processPlaylistPositionChangedEvent(_8);
- }else{
- if(_8.tagName=="PlayPositionChangedEvent"){
- processPlayPositionChangedEvent(_8);
- }else{
- if(_8.tagName=="ShuffleStateChangedEvent"){
- processShuffleStateChangedEvent(_8);
- }else{
- if(_8.tagName=="RepeatStateChangedEvent"){
- processRepeatStateChangedEvent(_8);
- }else{
- if(_8.tagName=="MediaLibraryChangedEvent"){
- processMediaLibraryChangedEvent();
- }else{
- if(_8.tagName=="SpeakerListChangedEvent"){
- processSpeakerListChangedEvent(_8);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- function processCurrentMediaChangedEvent(_9){
- var _a="";
- var _b="";
- var _c="";
- var _d=0;
- var _e=_9.getElementsByTagName("title");
- if(_e.length>0){
- _c=getData(_e[0]);
- }
- _e=_9.getElementsByTagName("artist");
- if(_e.length>0){
- _a=getData(_e[0]);
- }
- _e=_9.getElementsByTagName("album");
- if(_e.length>0){
- _b=getData(_e[0]);
- }
- _e=_9.getElementsByTagName("rating");
- if(_e.length>0){
- _d=getDataInt(_e[0]);
- }
- if(!ignoreNextRatingUpdate){
- ignoreNextRatingUpdate=false;
- if(currentRating!=_d){
- currentRating=_d;
- onRatingChanged(_d);
- }
- }else{
- ignoreNextRatingUpdate=false;
- }
- if((currentArtist!=_a)||(currentAlbum!=_b)||(currentTitle!=_c)){
- currentArtist=_a;
- currentAlbum=_b;
- currentTitle=_c;
- if(document.getElementById){
- var _f=document.getElementById("artist");
- _f.innerHTML=_a;
- var _10=document.getElementById("album");
- _10.innerHTML=_b;
- var _11=document.getElementById("title");
- _11.innerHTML=_c;
- }else{
- _a.innerHTML=_a;
- _b.innerHTML=_b;
- _c.innerHTML=_c;
- }
- sendRequest("<GetAlbumArtRequest></GetAlbumArtRequest>");
- }
- }
- function processPlayingStateChangedEvent(xml){
- var _13=xml.getElementsByTagName("playingState");
- if(_13.length>0){
- var _14="<img src=\"images/ctrl_play.png\">";
- var _15=getData(_13[0]);
- if(_15=="playing"){
- _14="<img src=\"images/ctrl_pause.png\">";
- }
- if(document.getElementById){
- message=document.getElementById("ctrl_play");
- message.innerHTML=_14;
- }else{
- ctrl_play.innerHTML=_14;
- }
- }
- }
- function processVolumeChangedEvent(xml){
- if(ignoreNextVolumeUpdate){
- ignoreNextVolumeUpdate=false;
- return;
- }
- var _17=xml.getElementsByTagName("volume");
- if(_17.length>0){
- var _18=getDataInt(_17[0]);
- if(currentVolume!=_18&&_18!=NaN){
- currentVolume=_18;
- onVolumeChanged(_18);
- }
- }
- }
- function processPlaylistChangedEvent(){
- getPlaylistItems(playlistStart,itemsPerPage);
- }
- function processPlaylistPositionChangedEvent(xml){
- var _1a=xml.getElementsByTagName("position");
- if(_1a.length>0){
- var _1b=playlistPosition;
- playlistPosition=getDataInt(_1a[0]);
- var _1c=document.getElementById("playlist_"+_1b);
- if(_1c){
- _1c.className="";
- }
- _1c=document.getElementById("playlist_"+playlistPosition);
- if(_1c){
- _1c.className="playing";
- }
- if(!showingPlaylist){
- if(playlistPosition<playlistStart||playlistPosition>(playlistStart+itemsPerPage)){
- var _1d=parseInt(playlistPosition/itemsPerPage);
- getPlaylistItems(_1d*itemsPerPage,itemsPerPage);
- }
- }
- }
- }
- function processPlayPositionChangedEvent(xml){
- var _1f=xml.getElementsByTagName("position");
- if(_1f.length>0){
- playPosition=getDataInt(_1f[0]);
- }
- }
- function processShuffleStateChangedEvent(xml){
- var _21=xml.getElementsByTagName("shuffleState");
- if(_21.length>0){
- if(getData(_21[0])=="true"){
- shuffleState=true;
- }else{
- shuffleState=false;
- }
- }
- var _22=document.getElementById("shufflecontrol");
- if(_22){
- if(shuffleState){
- _22.style.background="url(\"images/shuffle_on.png\") center no-repeat";
- }else{
- _22.style.background="url(\"images/shuffle_off.png\") center no-repeat";
- }
- }
- }
- function processRepeatStateChangedEvent(xml){
- var _24=xml.getElementsByTagName("repeatState");
- if(_24.length>0){
- if(getData(_24[0])=="true"){
- repeatState=true;
- }else{
- repeatState=false;
- }
- }
- var _25=document.getElementById("repeatcontrol");
- if(_25){
- if(repeatState){
- _25.style.background="url(\"images/repeat_on.png\") center no-repeat";
- }else{
- _25.style.background="url(\"images/repeat_off.png\") center no-repeat";
- }
- }
- }
- function processSpeakerListChangedEvent(xml){
- var _27=false;
- var _28=document.getElementById("speakercontrolcontainer");
- var _29=document.getElementById("speakerlist");
- var _2a="";
- var _2b=xml.getElementsByTagName("speaker");
- for(var i=0;i<_2b.length;i++){
- var _2d=_2b[i];
- var _2e=_2d.getElementsByTagName("name");
- if(_2e.length>0){
- var _2f=getData(_2e[0]);
- var _2e=_2d.getElementsByTagName("id");
- if(_2e.length>0){
- var id=getDataInt(_2e[0]);
- _2a+="<li onclick=\"handleSpeakerSelection("+id+")\">"+_2f+"</li>";
- }
- }
- }
- _29.innerHTML=_2a;
- if(_2b.length>1){
- _28.style.display="block";
- }else{
- _28.style.display="none";
- }
- }
- function processMediaLibraryChangedEvent(){
- browseLibrary(currentBrowsePath,0,itemsPerPage);
- }
- function processResponse(){
- try{
- if(http_request.readyState!=4){
- return;
- }
- if(timeoutRequest){
- clearTimeout(timeoutRequest);
- timeoutRequest=0;
- }
- currentRequest="";
- isRequestPending=false;
- if(!http_request.status||http_request.status!=200){
- return;
- }
- if(!http_request.responseXML){
- return;
- }
- var _31=http_request.responseXML.documentElement;
- if(!_31){
- return;
- }
- try{
- if(_31.tagName=="GetCurrentMediaResponse"){
- processCurrentMediaChangedEvent(_31);
- }else{
- if(_31.tagName=="GetPlayingStateResponse"){
- processPlayingStateChangedEvent(_31);
- }else{
- if(_31.tagName=="GetVolumeResponse"){
- processVolumeChangedEvent(_31);
- }else{
- if(_31.tagName=="GetShuffleStateResponse"){
- processShuffleStateChangedEvent(_31);
- }else{
- if(_31.tagName=="GetRepeatStateResponse"){
- processRepeatStateChangedEvent(_31);
- }else{
- if(_31.tagName=="GetAlbumArtResponse"){
- processGetAlbumArtResponse(_31);
- }else{
- if(_31.tagName=="MediaSearchResponse"){
- processMediaSearchResponse(_31);
- }else{
- if(_31.tagName=="BrowseLibraryResponse"){
- processBrowseLibraryResponse(_31);
- }else{
- if(_31.tagName=="GetPlaylistItemsResponse"){
- processGetPlaylistItemsResponse(_31);
- }else{
- if(_31.tagName=="GetPlaylistPositionResponse"){
- processPlaylistPositionChangedEvent(_31);
- }else{
- if(_31.tagName=="GetSpeakerListResponse"){
- processSpeakerListChangedEvent(_31);
- }else{
- processResponseForErrors(_31);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- catch(e){
- var _32="";
- if(_31.tagName){
- _32=_31.tagName;
- }
- writeLog("Error processing response "+_32,e);
- }
- if(pendingRequests.length>0){
- sendRequest(pendingRequests.pop());
- }
- }
- catch(e){
- writeLog("",e);
- return;
- }
- }
- function processResponseForErrors(xml){
- var _34=xml.getElementsByTagName("returnCode");
- if(_34.length>0){
- if(_34[0].firstChild){
- var _35=getDataInt(_34[0]);
- if(_35==106){
- alert("Please check \"Enable access for assistive devices\" on your Mac to use this feature.");
- }
- }
- }
- }
- function processGetAlbumArtResponse(xml){
- var _37="";
- var _38=xml.getElementsByTagName("artURL");
- if(_38.length>0){
- if(_38[0].firstChild){
- _37=getData(_38[0]);
- }
- }
- if(_37!=currentArtURL){
- currentArtURL=_37;
- if(onAlbumArtChanged){
- onAlbumArtChanged(currentArtURL);
- }
- }
- }
- function processBrowseLibraryResponse(xml){
- var _3a="<ul>";
- var _3b;
- var _3c="";
- var _3d="";
- var _3e=false;
- var _3f=false;
- var _40=-1;
- if(showingMediaLibAlphaJump){
- showMediaLibAlphaJump();
- }
- if(showingMediaLibSearch){
- showMediaLibSearch();
- }
- if(showingMediaLibSearchResults){
- showingMediaLibSearchResults=false;
- }
- if(showingMediaLib){
- hideAddressBar();
- }
- showingSearchResults=false;
- var _41=xml.getElementsByTagName("path");
- if(_41.length>0){
- if(_41[0].firstChild){
- currentBrowsePath=getData(_41[0]);
- }else{
- currentBrowsePath="";
- }
- }
- var _42="Media Library";
- if(currentBrowsePath.length>1){
- var pos=currentBrowsePath.lastIndexOf("\\");
- if(pos!=-1){
- pos++;
- _42=currentBrowsePath.substr(pos,currentBrowsePath.length-pos);
- if(_42.length>0){
- if(_42.charAt(_42.length-1)=="\\"){
- _42=_42.substr(0,_42.length-1);
- }
- }else{
- _42="Media Library";
- }
- }
- }
- if(document.getElementById){
- message=document.getElementById("libheadertitle");
- message.innerHTML=_42;
- }else{
- libheadertitle.innerHTML=_42;
- }
- _41=xml.getElementsByTagName("start");
- if(_41.length>0){
- mediaLibStart=getDataInt(_41[0]);
- }
- _41=xml.getElementsByTagName("totalCount");
- if(_41.length>0){
- mediaLibLength=getDataInt(_41[0]);
- }
- _41=xml.getElementsByTagName("alphaStartResult");
- if(_41.length>0){
- _40=getDataInt(_41[0]);
- }
- if(mediaLibLength>itemsPerPage){
- _3a+="<li>";
- if(mediaLibStart>0){
- _3a+="<div id=\"navprev\" onclick=\"mediaLibPrevPage()\">< Prev</div>";
- }else{
- _3a+="<div id=\"navprev\"> </div>";
- }
- _3a+="<div id=\"navalphajump\" onclick=\"showMediaLibAlphaJump()\">A-Z</div>";
- if((mediaLibStart+itemsPerPage)<mediaLibLength){
- _3a+="<div id=\"navnext\" onclick=\"mediaLibNextPage()\">Next ></div>";
- }else{
- _3a+="<div id=\"navnext\"> </div>";
- }
- _3a+="</li>";
- }
- var _44=xml.getElementsByTagName("result");
- for(var i=0;i<_44.length;i++){
- _3b=_44[i];
- var _46=null;
- _3e=false;
- _3f=true;
- _41=_3b.getElementsByTagName("type");
- if(_41.length>0){
- _3c=getData(_41[0]);
- if(_3c=="folder"){
- _3e=true;
- }
- }
- _41=_3b.getElementsByTagName("id");
- if(_41.length>0){
- _46=getData(_41[0]);
- }
- _41=_3b.getElementsByTagName("name");
- if(_41.length>0){
- var _42=getData(_41[0]);
- if(_3e){
- if(_42=="Music"){
- _3d="cd";
- }else{
- if(_42=="Videos"){
- _3d="video";
- }else{
- if(_42=="TV"){
- _3d="tv";
- }else{
- if(_42=="Genres"){
- _3d="genre";
- }else{
- if(_42=="Artists"){
- _3d="artist";
- }else{
- if(_42=="Albums"){
- _3d="album";
- }else{
- if(_42=="Playlists"){
- _3d="playlist";
- }else{
- if(_42=="Tracks"){
- _3d="music";
- }else{
- if(_42=="Podcasts"){
- _3d="podcast";
- }else{
- if(_42=="Radio"){
- _3d="podcast";
- }else{
- _3d="music";
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }else{
- if(_3c=="genre"){
- _3d="genre";
- }else{
- if(_3c=="artist"){
- _3d="artist";
- }else{
- if(_3c=="album"){
- _3d="album";
- }else{
- if(_3c=="podcast show"){
- _3d="podcast";
- }else{
- if(_3c=="tv series"){
- _3d="artist";
- _3f=false;
- }else{
- if(_3c=="playlist"){
- _3d="playlist";
- }else{
- if(_3c=="playlist folder"||_3c=="radio folder"){
- _3d="playlist_folder";
- _3f=false;
- }else{
- if(_3c=="info"){
- _3d="info";
- }else{
- _3d="music";
- }
- }
- }
- }
- }
- }
- }
- }
- }
- var _47=currentBrowsePath+"\\"+_42;
- _47=_47.replace(/\\/g,"\\\\");
- _47=_47.replace(/\'/g,"\\'");
- _47=_47.replace(/\"/g,""");
- _47="'"+_47+"'";
- _3a+="<li id=\"medialib_"+(mediaLibStart+i)+"\" ";
- if(!_46){
- if(!_3e&&_3f){
- _3a+="class=\"group\" ";
- }
- }else{
- if(_3c=="music"||_3c=="podcast"){
- _3a+="><div id=\"grouptitle\"";
- }
- }
- if(_46){
- _3a+="onclick=\"handlePlayItem(this, "+_46+")\"";
- }else{
- _3a+="onclick=\"handleBrowseLibrary(this, "+_47+")\"";
- }
- _3a+=">";
- if(_3d!=""){
- _3a+="<img src=\"images/"+_3d+".png\">";
- }
- _3a+=_42;
- if(!_46){
- if(!_3e&&_3f){
- _3a+="<div id=\"showactions\" onclick=\"showMediaLibActions("+_47+")\"></div>";
- }
- }else{
- if(_3c=="music"||_3c=="podcast"){
- _3a+="</div><div id=\"showactions\" onclick=\"handleSingleItemAdd(this, "+_46+")\"></div>";
- }
- }
- _3a+="</li>";
- }
- }
- if(mediaLibLength>itemsPerPage){
- _3a+="<li>";
- if(mediaLibStart>0){
- _3a+="<div id=\"navprev\" onclick=\"mediaLibPrevPage()\">< Prev</div>";
- }else{
- _3a+="<div id=\"navprev\"> </div>";
- }
- _3a+="<div id=\"navalphajump\" onclick=\"showMediaLibAlphaJump()\">A-Z</div>";
- if((mediaLibStart+itemsPerPage)<mediaLibLength){
- _3a+="<div id=\"navnext\" onclick=\"mediaLibNextPage()\">Next ></div>";
- }else{
- _3a+="<div id=\"navnext\"> </div>";
- }
- _3a+="</li>";
- }
- _3a+="</ul>";
- if(document.getElementById){
- message=document.getElementById("libcontents");
- message.innerHTML=_3a;
- }
- if(_40!=-1&&showingMediaLib){
- var _48=document.getElementById("medialib_"+_40);
- if(_48){
- slideTo(_48.offsetTop);
- }
- }
- }
- function processMediaSearchResponse(xml){
- var _4a="<ul>";
- var _4b;
- hideAddressBar();
- if(!showingMediaLibSearchResults){
- addBrowseHistoryEntry();
- showingMediaLibSearchResults=true;
- if(document.getElementById){
- message=document.getElementById("libheadertitle");
- message.innerHTML="Search";
- }else{
- libheadertitle.innerHTML="Search";
- }
- }
- _4c=xml.getElementsByTagName("start");
- if(_4c.length>0){
- mediaLibStart=getDataInt(_4c[0]);
- }else{
- mediaLibStart=0;
- }
- _4c=xml.getElementsByTagName("totalCount");
- if(_4c.length>0){
- mediaLibLength=getDataInt(_4c[0]);
- }
- var _4d=xml.getElementsByTagName("result");
- for(var i=0;i<_4d.length;i++){
- _4b=_4d[i];
- var _4f="";
- var _50=null;
- var _51="music";
- var _52="music";
- var _53="";
- var _4c=_4b.getElementsByTagName("type");
- if(_4c.length>0){
- _4f=getData(_4c[0]);
- _51=_4f;
- if(_51=="podcast show"){
- _51="podcast";
- }else{
- if(_51=="podcast"){
- _51="music";
- }
- }
- }
- _4c=_4b.getElementsByTagName("id");
- if(_4c.length>0){
- _50=getData(_4c[0]);
- }
- _4c=_4b.getElementsByTagName("name");
- if(_4c.length>0){
- var _54=getData(_4c[0]);
- _4a+="<li";
- if(_50){
- if(_4f!="playlist"){
- _4a+="><div id=\"grouptitle\" onclick=\"handlePlayItem(this, "+_50+")\"";
- }else{
- _4a+=" onclick=\"handlePlayItem(this, "+_50+")\"";
- }
- }else{
- _53="\\Music\\";
- if(_4f=="genre"){
- _53+="Genres\\";
- }else{
- if(_4f=="artist"){
- _53+="Artists\\";
- }else{
- if(_4f=="album"){
- _53+="Albums\\";
- }else{
- if(_4f=="podcast show"){
- _53="\\Podcasts\\";
- }
- }
- }
- }
- _53+=_54;
- _53=_53.replace(/\\/g,"\\\\");
- _53=_53.replace(/\'/g,"\\'");
- _53=_53.replace(/\"/g,""");
- _53="'"+_53+"'";
- _4a+=" class=\"group\" onclick=\"handleBrowseLibrary(this, "+_53+")\"";
- }
- _4a+="><img src=\"images/"+_51+".png\">"+_54;
- if(!_50){
- _4a+="<div id=\"showactions\" onclick=\"showMediaLibActions("+_53+")\"></div>";
- }else{
- if(_4f!="playlist"){
- _4a+="</div><div id=\"showactions\" onclick=\"handleSingleItemAdd(this, "+_50+")\"></div>";
- }
- }
- _4a+="</li>";
- }
- }
- _4a+="</ul>";
- if(document.getElementById){
- message=document.getElementById("libcontents");
- message.innerHTML=_4a;
- }else{
- libcontents.innerHTML=_4a;
- }
- showingSearchResults=true;
- }
- function processGetPlaylistItemsResponse(xml){
- var _56=0;
- var _57="<ul>";
- if(showingPlaylist){
- hideAddressBar();
- }
- var _58=xml.getElementsByTagName("start");
- if(_58.length>0){
- playlistStart=getDataInt(_58[0]);
- }else{
- playlistStart=0;
- }
- _58=xml.getElementsByTagName("totalCount");
- if(_58.length>0){
- playlistLength=getDataInt(_58[0]);
- }
- if(playlistLength>itemsPerPage){
- _57+="<li>";
- if(playlistStart>0){
- _57+="<div id=\"navprev\" onclick=\"playlistPrevPage()\">< Prev</div>";
- }
- if((playlistStart+itemsPerPage)<playlistLength){
- _57+="<div id=\"navnext\" onclick=\"playlistNextPage()\">Next ></div>";
- }
- _57+="</li>";
- }
- _58=xml.getElementsByTagName("item");
- for(i=0;i<_58.length;i++){
- _56=playlistStart+i;
- _57+="<li id=\"playlist_"+_56+"\" onclick=\"handlePlaylistJump(this, "+_56+")\"";
- if(_56==playlistPosition){
- _57+="class=\"playing\" ";
- }
- var _59="";
- var _5a="";
- var pos=getData(_58[i]).indexOf(" - ");
- if(pos!=-1){
- _59=getData(_58[i]).substr(0,pos);
- pos+=3;
- _5a=getData(_58[i]).substr(pos,getData(_58[i]).length-pos);
- }else{
- _5a=getData(_58[i]);
- }
- _57+=">"+_5a+" <span class=\"listArtist\">"+_59+"</span></li>";
- }
- if(_58.length<1){
- _57+="<li>No items</li>";
- }
- if(playlistLength>itemsPerPage){
- _57+="<li>";
- if(playlistStart>0){
- _57+="<div id=\"navprev\" onclick=\"playlistPrevPage()\">< Prev</div>";
- }
- if((playlistStart+itemsPerPage)<playlistLength){
- _57+="<div id=\"navnext\" onclick=\"playlistNextPage()\">Next ></div>";
- }
- _57+="</li>";
- }
- _57+="</ul>";
- if(document.getElementById){
- message=document.getElementById("playlistcontents");
- message.innerHTML=_57;
- }else{
- playlist.innerHTML=_57;
- }
- if(showPlaylistItemOnPageLoad){
- showPlaylistItemOnPageLoad=false;
- if(playlistPosition>=playlistStart&&playlistPosition<(playlistStart+itemsPerPage)){
- showCurrentPlaylistItem();
- }
- }
- }
- function playpause(){
- sendRequest("<PlayPauseRequest></PlayPauseRequest>");
- }
- function play(){
- sendRequest("<PlayRequest></PlayRequest>");
- }
- function pause(){
- sendRequest("<PauseRequest></PauseRequest>");
- }
- function stop(){
- sendRequest("<StopRequest></StopRequest>");
- }
- function prev(){
- sendRequest("<PreviousItemRequest></PreviousItemRequest>");
- }
- function next(){
- sendRequest("<NextItemRequest></NextItemRequest>");
- }
- function playItem(_5c){
- if(isNaN(Number(_5c))){
- sendRequest("<PlayMediaRequest><libPath>"+escape(_5c)+"</libPath></PlayMediaRequest>");
- }else{
- sendRequest("<PlayMediaRequest><id>"+_5c+"</id></PlayMediaRequest>");
- }
- }
- function playlistAdd(_5d){
- if(isNaN(Number(_5d))){
- sendRequest("<PlaylistAddRequest><libPath>"+escape(_5d)+"</libPath></PlaylistAddRequest>");
- }else{
- sendRequest("<PlaylistAddRequest><id>"+_5d+"</id></PlaylistAddRequest>");
- }
- }
- function setPlaylistPosition(_5e){
- sendRequest("<SetPlaylistPositionRequest><position>"+_5e+"</position></SetPlaylistPositionRequest>");
- }
- function refreshState(){
- sendRequest("<GetCurrentMediaRequest></GetCurrentMediaRequest>");
- }
- function browseLibrary(_5f,_60,_61,_62){
- _60=(_60==null)?0:_60;
- _61=(_61==null)?-1:_61;
- _62=(_62==null)?true:_62;
- var _63;
- if(isNaN(Number(_60))){
- _63="<BrowseLibraryRequest><start>"+_60+"</start><count>"+_61+"</count><path>"+escape(_5f)+"</path>";
- }else{
- if(_60<0){
- _60=0;
- }
- _63="<BrowseLibraryRequest><start>"+_60+"</start><count>"+_61+"</count><path>"+escape(_5f)+"</path>";
- }
- if(_62){
- _63+="<includeTotalCount>true</includeTotalCount>";
- }
- _63+="</BrowseLibraryRequest>";
- sendRequest(_63);
- }
- function searchLibrary(_64,_65,_66){
- _65=(_65==null)?0:_65;
- _66=(_66==null)?-1:_66;
- if(_65<0){
- _65=0;
- }
- sendRequest("<MediaSearchRequest><start>"+_65+"</start><count>"+_66+"</count><any>"+escape(_64)+"</any></MediaSearchRequest>");
- }
- function getPlaylistItems(_67,_68,_69){
- _67=(_67==null)?0:_67;
- _68=(_68==null)?-1:_68;
- _69=(_69==null)?true:_69;
- var _6a="<GetPlaylistItemsRequest><start>"+_67+"</start><count>"+_68+"</count>";
- if(_69){
- _6a+="<includeTotalCount>true</includeTotalCount>";
- }
- _6a+="</GetPlaylistItemsRequest>";
- sendRequest(_6a);
- }
- function toggleShuffleState(){
- sendRequest("<SetShuffleStateRequest><shuffleState>"+!shuffleState+"</shuffleState></SetShuffleStateRequest>");
- }
- function toggleRepeatState(){
- sendRequest("<SetRepeatStateRequest><repeatState>"+!repeatState+"</repeatState></SetRepeatStateRequest>");
- }
- function setVolume(_6b){
- if(_6b<0){
- _6b=0;
- }else{
- if(_6b>100){
- _6b=100;
- }
- }
- ignoreNextVolumeUpdate=true;
- currentVolume=_6b;
- sendRequest("<SetVolumeRequest><volume>"+_6b+"</volume></SetVolumeRequest>");
- }
- function volumeUp(){
- setVolume(currentVolume+volumeIncrement);
- onVolumeChanged(currentVolume);
- }
- function volumeDown(){
- setVolume(currentVolume-volumeIncrement);
- onVolumeChanged(currentVolume);
- }
- function setRating(_6c){
- if(_6c<0){
- _6c=0;
- }else{
- if(_6c>100){
- _6c=100;
- }
- }
- sendRequest("<SetTrackRatingRequest><rating>"+_6c+"</rating></SetTrackRatingRequest>");
- }
- function selectSpeaker(id){
- sendRequest("<SelectSpeakerRequest><id>"+id+"</id></SelectSpeakerRequest>");
- }
- function enableSpeaker(id,_6f){
- sendRequest("<EnableSpeakerRequest><id>"+id+"</id><enabled>"+_6f+"</enabled></EnableSpeakerRequest>");
- }
- function requestInitialState(){
- sendRequest("<GetPlayingStateRequest></GetPlayingStateRequest>");
- sendRequest("<GetCurrentMediaRequest></GetCurrentMediaRequest>");
- sendRequest("<GetVolumeRequest></GetVolumeRequest>");
- sendRequest("<GetShuffleStateRequest></GetShuffleStateRequest>");
- sendRequest("<GetRepeatStateRequest></GetRepeatStateRequest>");
- sendRequest("<GetPlaylistPositionRequest></GetPlaylistPositionRequest>");
- sendRequest("<GetSpeakerListRequest></GetSpeakerListRequest>");
- browseLibrary(currentBrowsePath,mediaLibStart,itemsPerPage);
- getPlaylistItems(0,itemsPerPage);
- }
- function testForMobileSafari(){
- try{
- if(navigator.userAgent){
- var pos=navigator.userAgent.indexOf(" Mobile/");
- if(pos!=-1){
- pos=navigator.userAgent.indexOf(" Safari/");
- if(pos!=-1){
- return true;
- }
- }
- }
- }
- catch(e){
- }
- return false;
- }
- function onLoad(){
- isMobileSafari=testForMobileSafari();
- if(isMobileSafari&&location.hash!=navCurrent&&location.hash!="NowPlaying"){
- navCurrent="NowPlaying";
- location.hash=navCurrent;
- }
- uiMonitor();
- setTimeout(setupApp,100);
- }
- function setupApp(){
- hideAddressBar();
- createQueue();
- setInterval(sleepMonitor,1000);
- setInterval(uiMonitor,300);
- var val=getCookie("useMultipleSpeakers");
- if(val!=null&&val=="true"&&!useMultipleSpeakers){
- toggleUseMultipleSpeakers();
- }
- }
- function hideAddressBar(){
- window.scrollTo(0,1);
- }
- function backToNowPlaying(){
- if(isMobileSafari){
- if(navHistory.length>0){
- history.back();
- }else{
- setLocation("",false);
- }
- }else{
- if(showingMediaLib){
- showMediaLib(false);
- }else{
- if(showingPlaylist){
- showPlaylist(false);
- }else{
- if(showingSpeakers){
- showSpeakers(false);
- }
- }
- }
- }
- }
- function showMediaLib(_72){
- if(document.getElementById){
- hideAddressBar();
- var _73=document.getElementById("medialib");
- var _74=document.getElementById("container");
- if(!showingMediaLib){
- setLocation("Media",_72);
- if(showingPlaylist){
- showPlaylist();
- }
- showingMediaLib=true;
- _73.style.overflow="visible";
- _73.style.visibility="visible";
- _74.style.overflow="visible";
- }else{
- if(showingMediaLibSearch){
- showMediaLibSearch();
- }
- if(showingMediaLibAlphaJump){
- showMediaLibAlphaJump();
- }
- showingMediaLib=false;
- _73.style.visibility="hidden";
- _73.style.overflow="hidden";
- _74.style.overflow="hidden";
- }
- }
- }
- function showPlaylist(_75){
- if(document.getElementById){
- var _76=document.getElementById("playlist");
- var _77=document.getElementById("container");
- if(!showingPlaylist){
- setLocation("Playlist",_75);
- if(showingMediaLib){
- showMediaLib(false);
- }
- hideAddressBar();
- _76.style.overflow="visible";
- _76.style.visibility="visible";
- _77.style.overflow="visible";
- showingPlaylist=true;
- }else{
- _76.style.visibility="hidden";
- _76.style.overflow="hidden";
- _77.style.overflow="hidden";
- showingPlaylist=false;
- hideAddressBar();
- }
- }
- }
- function showSpeakers(_78){
- if(document.getElementById){
- var _79=document.getElementById("speakers");
- var _7a=document.getElementById("container");
- if(!showingSpeakers){
- setLocation("Speakers",_78);
- hideAddressBar();
- _79.style.overflow="visible";
- _79.style.visibility="visible";
- _7a.style.overflow="visible";
- showingSpeakers=true;
- }else{
- _79.style.visibility="hidden";
- _79.style.overflow="hidden";
- _7a.style.overflow="hidden";
- showingSpeakers=false;
- hideAddressBar();
- }
- }
- }
- function showMediaLibSearch(){
- if(showingMediaLibAlphaJump){
- showMediaLibAlphaJump();
- }
- if(document.getElementById){
- var _7b=document.getElementById("libsearchfield");
- if(!showingMediaLibSearch){
- _7b.style.visibility="visible";
- var _7c=document.getElementById("searchInput");
- if(_7c){
- _7c.focus();
- }
- searchInputTimer=setInterval(searchInputMonitor,300);
- showingMediaLibSearch=true;
- }else{
- _7b.style.visibility="hidden";
- var _7c=document.getElementById("searchInput");
- _7c.value="";
- if(searchInputTimer){
- clearInterval(searchInputTimer);
- searchInputTimer=null;
- }
- showingMediaLibSearch=false;
- }
- }
- }
- function showMediaLibActions(_7d){
- if(document.getElementById){
- var _7e=document.getElementById("itemactions");
- currentActionItem=_7d;
- if(!showingMediaLibActions){
- hideAddressBar();
- _7e.style.visibility="visible";
- showingMediaLibActions=true;
- }else{
- _7e.style.visibility="hidden";
- showingMediaLibActions=false;
- hideAddressBar();
- }
- }
- }
- function showMediaLibAlphaJump(){
- if(document.getElementById){
- var _7f=document.getElementById("alphajump");
- if(!showingMediaLibAlphaJump){
- hideAddressBar();
- _7f.style.visibility="visible";
- showingMediaLibAlphaJump=true;
- }else{
- _7f.style.visibility="hidden";
- showingMediaLibAlphaJump=false;
- hideAddressBar();
- }
- }
- }
- function showCurrentPlaylistItem(){
- if(playlistPosition<playlistStart||playlistPosition>=(playlistStart+itemsPerPage)){
- var _80=parseInt(playlistPosition/itemsPerPage);
- getPlaylistItems(_80*itemsPerPage,itemsPerPage);
- showPlaylistItemOnPageLoad=true;
- return;
- }
- if(!showingPlaylist){
- showPlaylist();
- setTimeout(showCurrentPlaylistItem,100);
- return;
- }
- var _81=document.getElementById("playlist_"+playlistPosition);
- if(_81){
- window.scrollTo(0,_81.offsetTop);
- }
- }
- function addBrowseHistoryEntry(){
- var _82=new BrowseHistoryEntry();
- _82.start=mediaLibStart;
- _82.search=showingMediaLibSearchResults;
- if(!_82.search){
- _82.path=currentBrowsePath;
- }else{
- _82.path=currentSearchKeywords;
- }
- browseHistory.push(_82);
- }
- function navigateLibBack(){
- if(browseHistory.length<1){
- backToNowPlaying();
- return;
- }
- var _83=browseHistory.pop();
- if(!_83.search){
- browseLibrary(_83.path,_83.start,itemsPerPage);
- }else{
- if(!showingMediaLibSearchResults){
- showingMediaLibSearchResults=true;
- if(document.getElementById){
- message=document.getElementById("libheadertitle");
- message.innerHTML="Search";
- }else{
- libheadertitle.innerHTML="Search";
- }
- }
- currentSearchKeywords=_83.path;
- searchLibrary(_83.path,_83.start,itemsPerPage);
- }
- }
- function onAlbumArtChanged(url){
- if(url==""){
- url="images/no_artwork.jpg";
- }
- var _85="";
- if(url!=""){
- _85="<img id=\"artwork\" src=\""+url+"\">";
- }
- if(document.getElementById){
- var _86=document.getElementById("albumart");
- _86.innerHTML=_85;
- }else{
- _86.innerHTML=_85;
- }
- }
- function onRatingChanged(_87){
- var _88=_87/20;
- for(i=1;i<=5;i++){
- var _89=document.getElementById("star"+i);
- if(_89){
- if(i<=_88){
- _89.className="starred";
- }else{
- _89.className="";
- }
- }
- }
- }
- function onVolumeChanged(_8a){
- var _8b=document.getElementById("volumecontrol");
- var _8c=document.getElementById("volumecontrol_on");
- if(_8c&&_8b){
- var _8d=(_8b.offsetWidth-20);
- _8d*=(currentVolume/100);
- _8c.style.width=_8d+"px";
- }
- }
- function searchInput_keyUp(){
- if(!showingMediaLibSearch){
- return;
- }
- var _8e=document.getElementById("searchInput");
- if(_8e.value.length>2){
- currentSearchKeywords=_8e.value;
- searchLibrary(_8e.value,0,itemsPerPage);
- }else{
- var _8f=document.getElementById("libcontents");
- _8f.innerHTML="";
- }
- }
- function toggleControls(){
- var _90=document.getElementById("subcontrols");
- hideAddressBar();
- if(!showingSubControls){
- _90.style.visibility="visible";
- showingSubControls=true;
- }else{
- _90.style.visibility="hidden";
- showingSubControls=false;
- }
- }
- function handleBrowseLibrary(_91,_92){
- hideAddressBar();
- if(showingMediaLib){
- addBrowseHistoryEntry();
- }
- browseLibrary(_92,0,itemsPerPage);
- }
- function handlePlayItem(_93,_94){
- backToNowPlaying();
- playItem(_94);
- }
- function handlePlaylistJump(_95,_96){
- backToNowPlaying();
- setPlaylistPosition(_96);
- }
- function handleRating(_97){
- currentRating=_97;
- onRatingChanged(_97);
- setRating(_97);
- }
- function handleActionPlay(){
- playItem(currentActionItem);
- showMediaLibActions();
- }
- function handleActionAdd(){
- playlistAdd(currentActionItem);
- showMediaLibActions();
- }
- function handleSingleItemAdd(_98,_99){
- _98.className="off";
- playlistAdd(_99);
- }
- function handleSpeakerSelection(id){
- if(!useMultipleSpeakers){
- backToNowPlaying();
- selectSpeaker(id);
- }else{
- enableSpeaker(id,true);
- }
- }
- function toggleUseMultipleSpeakers(){
- useMultipleSpeakers=!useMultipleSpeakers;
- var _9b=document.getElementById("speakermsg");
- var _9c=document.getElementById("multiplespeakerbtn");
- _9c.setAttribute("enabled",useMultipleSpeakers);
- if(useMultipleSpeakers){
- _9b.innerHTML="Tap on a speaker name to toggle its audio on or off.";
- }else{
- _9b.innerHTML="Tap on a speaker name to send all audio to that speaker.";
- }
- if(useMultipleSpeakers){
- setCookie("useMultipleSpeakers","true",365);
- }else{
- deleteCookie("useMultipleSpeakers");
- }
- }
- function mediaLibPrevPage(){
- browseLibrary(currentBrowsePath,mediaLibStart-itemsPerPage,itemsPerPage,false);
- }
- function mediaLibNextPage(){
- browseLibrary(currentBrowsePath,mediaLibStart+itemsPerPage,itemsPerPage,false);
- }
- function mediaLibJumpToLetter(_9d){
- browseLibrary(currentBrowsePath,_9d,itemsPerPage,false);
- if(showingMediaLibAlphaJump){
- showMediaLibAlphaJump();
- }
- }
- function playlistPrevPage(){
- getPlaylistItems(playlistStart-itemsPerPage,itemsPerPage,false);
- }
- function playlistNextPage(){
- getPlaylistItems(playlistStart+itemsPerPage,itemsPerPage,false);
- }
- function adjustVolume(_9e){
- var _9f=_9e.offsetX?(_9e.offsetX):_9e.pageX-document.getElementById("volumecontrol").offsetLeft;
- var _a0=document.getElementById("volumecontrol");
- var _a1=document.getElementById("volumecontrol_on");
- if(_a1&&_a0){
- var _a2;
- if(_9f>10&&_9f<_a0.offsetWidth-10){
- _a2=_9f/(_a0.offsetWidth-20);
- _a2*=100;
- _a2=parseInt(_a2);
- }else{
- if(_9f<10){
- _a2=0;
- }else{
- _a2=100;
- }
- }
- setVolume(_a2);
- onVolumeChanged(currentVolume);
- }
- }
- function setLocation(_a3,_a4){
- if(!isMobileSafari){
- return;
- }
- if(_a4==null||_a4==true){
- navHistory.push(location.hash);
- }
- navCurrent=_a3;
- location.hash=navCurrent;
- }
- function slideTo(pos){
- setTimeout(function(){
- var _a6=100;
- var _a7=setInterval(slide,0);
- function slide(){
- _a6-=slideSpeed;
- if(_a6<=0){
- _a6=0;
- clearInterval(_a7);
- }
- var x=((100-_a6)/100)*pos;
- scrollTo(0,x);
- }
- },0);
- }
- function setCookie(_a9,_aa,_ab){
- var _ac="";
- if(_ab){
- var _ad=new Date();
- _ad.setTime(_ad.getTime()+(_ab*24*60*60*1000));
- _ac="; expires="+_ad.toGMTString();
- }
- document.cookie=_a9+"="+_aa+_ac+"; path=/";
- }
- function getCookie(_ae){
- _ae+="=";
- var _af=document.cookie.split(";");
- for(var i=0;i<_af.length;i++){
- var _b1=_af[i];
- while(_b1.charAt(0)==" "){
- _b1=_b1.substring(1,_b1.length);
- }
- if(_b1.indexOf(_ae)==0){
- return _b1.substring(_ae.length,_b1.length);
- }
- }
- return null;
- }
- function deleteCookie(_b2){
- setCookie(_b2,"",-1);
- }
- function searchInputMonitor(){
- if(!showingMediaLibSearch){
- return;
- }
- var _b3=document.getElementById("searchInput");
- if(_b3.value!=searchInput){
- searchInput=_b3.value;
- if(searchInput.length>2){
- currentSearchKeywords=searchInput;
- searchLibrary(searchInput,0,itemsPerPage);
- }else{
- var _b4=document.getElementById("libcontents");
- _b4.innerHTML="";
- }
- }
- }
- function uiMonitor(){
- if(!isMobileSafari){
- return;
- }
- if(currentWindowWidth!=window.innerWidth){
- currentWindowWidth=window.innerWidth;
- var _b5=(currentWindowWidth==320)?"portrait":"landscape";
- document.body.setAttribute("orientation",_b5);
- if(!showingPlaylist&&!showingMediaLib){
- hideAddressBar();
- }
- }
- if(location.hash!=navCurrent){
- var _b6=location.hash.substr(navHash.length);
- if(_b6==navCurrent){
- navCurrent=location.hash;
- verifyQueueActive();
- return;
- }
- navCurrent=location.hash;
- if(navHistory.length>0&&location.hash==navHistory[navHistory.length-1]){
- navHistory.pop();
- }else{
- navHistory.push(location.hash);
- }
- if(_b6=="Media"){
- if(!showingMediaLib){
- showMediaLib(false);
- }
- }else{
- if(_b6=="Playlist"){
- if(!showingPlaylist){
- showPlaylist(false);
- }
- }else{
- if(_b6=="Speakers"){
- if(!showingSpeakers){
- showSpeakers(false);
- }
- }else{
- if(showingMediaLib){
- showMediaLib(false);
- }else{
- if(showingPlaylist){
- showPlaylist(false);
- }else{
- if(showingSpeakers){
- showSpeakers(false);
- }
- }
- }
- }
- }
- }
- verifyQueueActive();
- }
- }
- function sleepMonitor(){
- var _b7=new Date();
- if((_b7-lastMonitorTime>7000)&&(!linkRecoveryActive)){
- enterLinkRecovery();
- }
- lastMonitorTime=_b7;
- }
- function enterLinkRecovery(){
- if(linkRecoveryActive){
- return;
- }
- linkRecoveryRequests.splice(0,linkRecoveryRequests.length);
- exitLinkRecovery();
- if(timerQueue){
- clearInterval(timerQueue);
- timerQueue=0;
- }
- if(http_request){
- http_request.abort();
- http_request=null;
- }
- isRequestPending=false;
- pendingRequests.splice(0,pendingRequests.length);
- linkRecoveryActive=true;
- linkRecoveryStart=new Date();
- timeoutCheckQueue=setTimeout(checkQueue,2000);
- }
- function exitLinkRecovery(){
- if(timeoutCheckQueue){
- clearTimeout(timeoutCheckQueue);
- timeoutCheckQueue=0;
- }
- if(timeoutPing){
- clearTimeout(timeoutPing);
- timeoutPing=0;
- }
- if(timeoutPingResponse){
- clearTimeout(timeoutPingResponse);
- timeoutPingResponse=0;
- }
- if(timeoutVerifyPingQueue){
- clearTimeout(timeoutVerifyPingQueue);
- timeoutVerifyPingQueue=0;
- }
- if(timerQueue==0){
- if(usePersistentConnection){
- timerQueue=setInterval(verifyQueueActive,5000);
- }else{
- timerQueue=setInterval(getQueuedEvents,1000);
- }
- }
- if(link_request&&link_request.readyState!=4){
- link_request.abort();
- link_request=null;
- }
- isLinkRequestPending=false;
- linkRecoveryActive=false;
- while(linkRecoveryRequests.length>0){
- sendRequest(linkRecoveryRequests.pop());
- }
- }
- function checkQueue(){
- if(lastEventTime<=linkRecoveryStart){
- pingServer();
- }else{
- exitLinkRecovery();
- }
- }
- function pingServer(){
- if(isLinkRequestPending&&link_request){
- link_request.abort();
- }
- link_request=createHTTPRequest();
- isLinkRequestPending=true;
- receivedPingResponse=false;
- link_request.open("POST","/q",true);
- link_request.setRequestHeader("Cache-Control","no-cache");
- link_request.setRequestHeader("If-Modified-Since","Wed, 15 Nov 1995 00:00:00 GMT");
- link_request.onreadystatechange=processLinkResponse;
- link_request.send("action=ping&id="+queueID);
- timeoutPingResponse=setTimeout(verifyPingResponse,1000);
- }
- function verifyPingResponse(){
- if(!receivedPingResponse){
- if(queue_request){
- queue_request.abort();
- queue_request=null;
- isQueueRequestPending=false;
- }
- pingServer();
- }
- }
- function processLinkResponse(){
- try{
- if(link_request.readyState!=4){
- return;
- }
- isLinkRequestPending=false;
- if(!link_request.status||link_request.status!=200){
- return;
- }
- if(!link_request.responseText){
- return;
- }
- if(link_request.responseText=="ok"){
- if(timeoutPingResponse){
- clearTimeout(timeoutPingResponse);
- timeoutPingResponse=0;
- }
- receivedPingResponse=true;
- if(linkRecoveryActive){
- if(timeoutVerifyPingQueue){
- clearTimeout(timeoutVerifyPingQueue);
- }
- timeoutVerifyPingQueue=setTimeout(verifyQueuePing,2000);
- }
- getQueuedEvents();
- }else{
- if(link_request.responseText=="not found"){
- if(linkRecoveryActive){
- exitLinkRecovery();
- }
- createQueue();
- }
- }
- }
- catch(e){
- isLinkRequestPending=false;
- writeLog("",e);
- return;
- }
- }
- function verifyQueuePing(){
- exitLinkRecovery();
- if(lastEventTime<=linkRecoveryStart){
- if(queue_request){
- queue_request.abort();
- queue_request=null;
- isQueueRequestPending=false;
- }
- createQueue();
- }
- }
- function getData(_b8){
- if(_b8.firstChild){
- return _b8.firstChild.data;
- }else{
- return "";
- }
- }
- function getDataInt(_b9){
- if(_b9.firstChild){
- return parseInt(_b9.firstChild.data);
- }else{
- return -1;
- }
- }
- function writeLog(msg,e){
- if(!loggingEnabled){
- return;
- }
- try{
- if(e){
- if(e.lineNumber){
- msg+=": "+e.toString()+" at line "+e.lineNumber+" of "+e.fileName+"\nstack:\n"+e.stack;
- }else{
- msg+=": "+e.toString();
- }
- }
- console.log(msg);
- }
- catch(loge){
- }
- }
-
-